<template>
	<view class="content" v-if="Object.keys(userInfo).length > 0">
		<view class="baibox">
			<view class="baili" @click="setdata(0)">
				<view class="left">
					<view class="title">
						价格设置
					</view>
				</view>
				<view class="cenbox">
					<scroll-view scroll-x="true" class="qianbox" style="font-size: 12px;color:#999;">
						请输入 
					</scroll-view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			<view class="baili" @click="setdata(0)">
				<view class="left">
					<view class="title">
						字数设置
					</view>
				</view>
				<view class="cenbox">
					<scroll-view scroll-x="true" class="qianbox" style="font-size: 12px;color:#999;">
						请输入 
					</scroll-view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			
			
			<view class="baili other_wrap" @click="setdata(0)">
				<view class="item">
					<view class="left">
						<view class="title">
							标签匹配
						</view>
					</view>
					<view class="tag_box">
						<view class="tag_item">
							#写意
						</view>
					</view>
					<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
				</view>
				
				<view class="tip">
					当用户通过标签匹配搜索相同标签时，可被用户搜索
				</view>
			</view>
		</view>
		
		<view class="ti" @click="submit(true)">
			发起审核
		</view>
			
		<u-popup :show="show" mode="center" @close="close" @open="open">
			<view class="mask">
				<view class="jatitle" v-if="type==0">
					价格设置
				</view>
				<input v-if="type==0" type="digit" class="japut" placeholder="请输入价格(币)"
					v-model="userInfo.writer_user_config.word_price">
					
					
				<view class="jatitle" v-if="type==1">
					字数设置
				</view>
				<picker v-if="type==1" class="japut" @change="bindPickerChange" :value="index" :range="array">
					{{array[index]}}
				</picker>
				<view class="qubox">
					<view class="quli" @click="show = false">
						取消
					</view>
					<view class="que" @click="setting">
						确定
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				type:0,
				// 字数
				array: this.$db.get('config').word_count_label,
				index: 0,
				// 开关
				value: false,
				// 弹框
				show: false,
				userInfo: {}
			}
		},
		onLoad() {

		},

		onShow() {
			this.getUserInfo()
		},
		methods: {
			
			setdata(type){
				this.type = type;
				this.show= true;
			},
			setting() {
				var that = this
				var prams = {
					word_price: this.userInfo.writer_user_config.word_price,
					word_count: this.userInfo.writer_user_config.word_count,
				}

				if (!prams['word_price']) {
					this.$common.errorToShow('请输入价格', () => {
						this.userInfo.writer_user_config.order_receiving_status = 0
					}, 1000)
					return
				}

				this.$api.default.request('user/saveWriterUserConfig', prams).then((res) => {
					if (res.code == 1) {
						that.$common.successToShow(res.msg, () => {
							that.show = false
						})
					}
				})

			},
			submit(show = false) {
				var that = this
				var prams = {
					order_receiving_status: this.userInfo.writer_user_config.order_receiving_status,
				}

				if (!this.userInfo.writer_user_config.hasOwnProperty('uid')) {
					prams['uid'] = this.userInfo.writer_user_config.uid
				}

				this.$api.default.request('good/list', {
					page: 1
				}).then((res) => {
					if (res.code) {
						if (res.data.total) {
							that.$api.default.request('user/saveWriterUserConfig', prams).then((res) => {
								if (res.code == 1) {
									that.$common.successToShow(res.msg, () => {
										if (show) {
											uni.navigateBack()
										}
									})
								} else {
									that.$common.errorToShow(res.msg, () => {
										that.userInfo.writer_user_config.order_receiving_status = 0
									})
								}
							})
						} else {
							that.$common.errorToShow('请先上传橱窗商品', () => {
								that.userInfo.writer_user_config.order_receiving_status = 0
							})
						}
					}
				})
			},
			getUserInfo() {
				this.$api.default.request('user/userInfo', {}, 'POST', false).then((res) => {
					if (res.code) {
						this.userInfo = res.user

						this.userInfo.writer_user_config.word_count = this.userInfo.writer_user_config.word_count ?
							this.userInfo.writer_user_config.word_count : this.array[0]
						this.array.forEach((item, index) => {
							if (res.user.writer_user_config.word_count == item) {
								this.index = index
							}
						})
					}
				})
			},
			change(e) {
				this.xuan = !this.xuan
				this.submit()
			},
			// 弹框
			open() {

			},
			close() {
				this.show = false
			},
			// 字数
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
				this.userInfo.writer_user_config.word_count = this.array[e.detail.value]
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {

		.baibox {
			background-color: #FFFFFF;
			padding: 0 30rpx;
			margin-bottom: 20rpx;

			.baili:last-child {
				border-bottom: none;
			}
			.other_wrap{
				flex-direction: column;
				align-items: initial !important;
				.item{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.tag_box{
						flex: 1;
						padding: 0 32rpx;
						.tag_item{
							font-size: 24rpx;
							font-weight: normal;
							color: #3D3D3D;
							padding: 0px 12rpx 4rpx 8rpx;
							background: rgba(153, 153, 153, 0.1);
							max-width: 84rpx;
							border-radius: 178rpx;
							text-align: center;
							margin-left: 16rpx;
						}
					}
				}
				.other_ipt{
					font-size: 24rpx;
					color: #999999;
				}
				.tip{
					font-size: 24rpx;
					font-weight: normal;
					color: #999999;
				}
			}
			.baili {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 40rpx 0;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);
				.other{
					font-size: 28rpx;
					font-weight: normal;
					color: #3D3D3D;
					padding-right: 60rpx;
				}
				.zhan {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
				}

				.left {
					flex-shrink: 0;

					.title {
						font-size: 28rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
						padding-bottom: 10rpx;
						span{
							color: red;
							margin-left: 7rpx
						}
					}

					.txt {
						font-size: 24rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #3D3D3D;
					}
				}

				.centxt {
					font-size: 28rpx;
					font-weight: normal;
					text-align: right;
					letter-spacing: 0em;
					color: #999999;
					width: 440rpx;
				}

				.cenbox {
					flex-grow: 1;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					padding: 0 16rpx;

					.headpic {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
					}

					.centxt {
						font-size: 28rpx;
						font-weight: normal;
						text-align: right;
						letter-spacing: 0em;
						color: #999999;
						width: 440rpx;
					}

					.qianbox {
						text-align: right;
						width: 450rpx;
						white-space: nowrap;

						.qli {
							background: rgba(153, 153, 153, 0.1);
							padding: 3rpx 12rpx 4rpx 8rpx;
							border-radius: 178px;
							font-size: 24rpx;
							color: #3D3D3D;
							display: inline-block;
						}

						.qli:not(:first-child) {
							margin-left: 16rpx;
						}
					}
				}

				.rarr {
					width: 40rpx;
					height: 40rpx;
					flex-shrink: 0;
				}
			}
		}

		.ti {
			width: 630rpx;
			height: 86rpx;
			border-radius: 8px;
			line-height: 86rpx;
			margin: 0 auto;
			opacity: 1;
			background: #45C4B0;
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
			letter-spacing: 0em;
			color: #FFFFFF;
		}

		.mask {
			background-color: #FFFFFF;
			width: 500rpx;
			border-radius: 10px;
			padding: 30rpx;

			.jatitle {
				font-size: 28rpx;
				font-weight: bold;
				padding-bottom: 20rpx;
			}

			.japut {
				border-bottom: 1px solid #f2f2f2;
				font-size: 24rpx;
				color: #3D3D3D;
				padding-bottom: 15rpx;
				margin-bottom: 30rpx;
			}

			.qubox {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.quli {
					border-radius: 8px;
					border: 1px solid #eeeeee;
					font-size: 24rpx;
					color: #999999;
					width: 220rpx;
					text-align: center;
					height: 60rpx;
					line-height: 60rpx;
				}

				.que {
					border-radius: 8px;
					border: 1px solid #45C4B0;
					background-color: #45C4B0;
					font-size: 24rpx;
					color: #ffffff;
					text-align: center;
					width: 220rpx;
					height: 60rpx;
					line-height: 60rpx;
				}
			}
		}
	}
</style>